package com.taxigang.server;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import com.allen_sauer.gwt.log.client.Log;
import com.taxigang.persistence.EMF;

public class ExceptionHandler {
	EntityManager em = EMF.get().createEntityManager();

	public EntityManager getEntityManager() {return em; }

	public boolean add(Exception ex) {
		Log.error(ex.getMessage());
		if (true){
			ex.printStackTrace();
		}
		EntityManager em = getEntityManager();
		try{
			EntityTransaction transaction = em.getTransaction();
			transaction.begin();
			em.persist(ex); 
			transaction.commit();
		} finally {
			//em.close();
			return false;
		}
	}




	public Exception get(long id) {
		return  em.find(Exception.class, id);
	}
}
